<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/9/13
  Time: 10:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../common/include.jsp" %>
<html>
<head>
    <title>Title</title>
    <script src="components/multiselect/multiple-select.js"></script>

    <link href="components/multiselect/multiple-select.css?2017" rel="stylesheet">
    <script>
        $(function () {
            $('#programmer').change(function () {
                console.log($(this).val());
            }).multipleSelect({
                width: '100%'
            });

            //时间选择器
            laydate.render({
                elem: '#beginTime'
                , type: 'datetime'
            });
            //时间选择器
            laydate.render({
                elem: '#endTime'
                , type: 'datetime'
            });
        });


    </script>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content  animated fadeInRight">
    <form class="form-horizontal" id="demandForm" name="demandForm">
        <input type="hidden" id="demId" name="demId" value="${tDemandSource.id}">
        <input type="hidden" id="status" name="status" value="${tDemandSource.status}">
        <input type="hidden" id="isReceive" name="isReceive" value="${isReceive}">
        <div class="tabs-container">
            <fieldset>

                <div class="form-group">

                    <label class="col-sm-2 control-label">开发人员：</label>
                    <div class="col-sm-2">
                        <select  multiple="multiple"  name="programmer" id="programmer">

                            <c:forEach items="${users}" var="user" varStatus="indexStr">
                                <option <c:if test="${indexStr.index == 0}"> selected </c:if> value="${user.id}">${user.realName}</option>

                            </c:forEach>
                        </select>
                    </div>

                </div>
                <div class="form-group">

                    <label class="col-sm-2 control-label">开始时间：</label>
                    <div class="col-sm-4">
                        <div class="input-group date">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                            <input readonly name="beginTime" id="beginTime"
                                   type="text"
                                   class="form-control">

                        </div>


                    </div>
                </div>
                <div class="form-group">

                    <label class="col-sm-2 control-label">完成时间：</label>
                    <div class="col-sm-4">
                        <div class="input-group date">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                            <input readonly name="endTime" id="endTime"
                                   type="text"
                                   class="form-control">

                        </div>

                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-2 control-label">处理意见：</label>
                    <div class="col-sm-7">
                                    <textarea id="remark" name="remark"
                                              class="form-control"
                                              rows="5"></textarea>
                    </div>
                </div>

            </fieldset>
            <fieldset>
                <div class="form-group">
                    <div class="col-sm-7" style="text-align: center;">

                        <input value="提交" class="btn  btn-primary" type="button" id="submitBtn">
                        <button id="closeBut" onclick="closeWin()" class="btn  btn--white" type="button">关闭</button>
                    </div>
                </div>
            </fieldset>
        </div>
    </form>
</div>


<script>
    function closeWin() {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
    }

    $(document).ready(function () {
        $("#demandForm").validate({

            rules: {

                beginTime: {
                    required: true,
                },
                endTime: {
                    required: true,
                }
            },
            messages: {

                beginTime: {
                    required: '请填写计划时间'
                },
                endTime: {
                    required: '请填写计划时间'
                }
            }
        });
    });

    $("#submitBtn").click(function () {

        if ($("#demandForm").valid()) {

            var remark = $("#remark").val();
            var isReceive = $("#isReceive").val();
            var beginTime = $("#beginTime").val();
            var endTime = $("#endTime").val();
            var status = $("#status").val();
            //var programmerId = $("#programmer").val();
            //var programmer = $("#programmer").find("option:selected").text();

            var programmerId = $("#programmer").multipleSelect("getSelects")+"";
            var programmer = $("#programmer").multipleSelect("getSelects","text")+"";
            var demandId = $("#demId").val();

            var args = {
                "status": status,
                "demandId": demandId,
                "isReceive": isReceive,
                "remark": remark,
                "programmer": programmer,
                "programmerId": programmerId,
                "beginTime": beginTime,
                "endTime": endTime
            }

            var url = "expPlan.html";
            //加载进度条
            layer.load(2, {
                shade: [0.2, '#999999'] //0.1透明度的白色背景
            });
            $.post(url, args, function (data) {
                data = jQuery.parseJSON(data);
                //保存成功
                if (data.code == 1) {
                    layer.closeAll('loading');
                    layer.alert(data.msg,
                        function () {
                            parent.location.reload();
                        });


                } else {
                    //失败
                    layer.alert("失败");
                    layer.closeAll('loading');
                }
            });
        }
    });

</script>
</body>
</html>
